summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Chapter 4 - Clustering and classification

First we load the “Boston” data from MASS package and explore it.

library(MASS)
data("Boston")
str(Boston)
## 'data.frame':    506 obs. of  14 variables:
##  $ crim   : num  0.00632 0.02731 0.02729 0.03237 0.06905 ...
##  $ zn     : num  18 0 0 0 0 0 12.5 12.5 12.5 12.5 ...
##  $ indus  : num  2.31 7.07 7.07 2.18 2.18 2.18 7.87 7.87 7.87 7.87 ...
##  $ chas   : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ nox    : num  0.538 0.469 0.469 0.458 0.458 0.458 0.524 0.524 0.524 0.524 ...
##  $ rm     : num  6.58 6.42 7.18 7 7.15 ...
##  $ age    : num  65.2 78.9 61.1 45.8 54.2 58.7 66.6 96.1 100 85.9 ...
##  $ dis    : num  4.09 4.97 4.97 6.06 6.06 ...
##  $ rad    : int  1 2 2 3 3 3 5 5 5 5 ...
##  $ tax    : num  296 242 242 222 222 222 311 311 311 311 ...
##  $ ptratio: num  15.3 17.8 17.8 18.7 18.7 18.7 15.2 15.2 15.2 15.2 ...
##  $ black  : num  397 397 393 395 397 ...
##  $ lstat  : num  4.98 9.14 4.03 2.94 5.33 ...
##  $ medv   : num  24 21.6 34.7 33.4 36.2 28.7 22.9 27.1 16.5 18.9 ...
summary(Boston)
##       crim                zn             indus            chas        
##  Min.   : 0.00632   Min.   :  0.00   Min.   : 0.46   Min.   :0.00000  
##  1st Qu.: 0.08204   1st Qu.:  0.00   1st Qu.: 5.19   1st Qu.:0.00000  
##  Median : 0.25651   Median :  0.00   Median : 9.69   Median :0.00000  
##  Mean   : 3.61352   Mean   : 11.36   Mean   :11.14   Mean   :0.06917  
##  3rd Qu.: 3.67708   3rd Qu.: 12.50   3rd Qu.:18.10   3rd Qu.:0.00000  
##  Max.   :88.97620   Max.   :100.00   Max.   :27.74   Max.   :1.00000  
##       nox               rm             age              dis        
##  Min.   :0.3850   Min.   :3.561   Min.   :  2.90   Min.   : 1.130  
##  1st Qu.:0.4490   1st Qu.:5.886   1st Qu.: 45.02   1st Qu.: 2.100  
##  Median :0.5380   Median :6.208   Median : 77.50   Median : 3.207  
##  Mean   :0.5547   Mean   :6.285   Mean   : 68.57   Mean   : 3.795  
##  3rd Qu.:0.6240   3rd Qu.:6.623   3rd Qu.: 94.08   3rd Qu.: 5.188  
##  Max.   :0.8710   Max.   :8.780   Max.   :100.00   Max.   :12.127  
##       rad              tax           ptratio          black       
##  Min.   : 1.000   Min.   :187.0   Min.   :12.60   Min.   :  0.32  
##  1st Qu.: 4.000   1st Qu.:279.0   1st Qu.:17.40   1st Qu.:375.38  
##  Median : 5.000   Median :330.0   Median :19.05   Median :391.44  
##  Mean   : 9.549   Mean   :408.2   Mean   :18.46   Mean   :356.67  
##  3rd Qu.:24.000   3rd Qu.:666.0   3rd Qu.:20.20   3rd Qu.:396.23  
##  Max.   :24.000   Max.   :711.0   Max.   :22.00   Max.   :396.90  
##      lstat            medv      
##  Min.   : 1.73   Min.   : 5.00  
##  1st Qu.: 6.95   1st Qu.:17.02  
##  Median :11.36   Median :21.20  
##  Mean   :12.65   Mean   :22.53  
##  3rd Qu.:16.95   3rd Qu.:25.00  
##  Max.   :37.97   Max.   :50.00
names(Boston)
##  [1] "crim"    "zn"      "indus"   "chas"    "nox"     "rm"      "age"    
##  [8] "dis"     "rad"     "tax"     "ptratio" "black"   "lstat"   "medv"

The “Boston”-data is comprised of 506 observations of 14 different variables. The “Names()”-function provides the names of the variables included. The function “Summary()” produces the distributions of each variable.

Now we explore the relationship between variables.

library(corrplot)
## corrplot 0.84 loaded
library(tidyverse)
## ── Attaching packages ───────────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.1.0     ✔ purrr   0.2.5
## ✔ tibble  1.4.2     ✔ dplyr   0.7.7
## ✔ tidyr   0.8.2     ✔ stringr 1.3.1
## ✔ readr   1.2.1     ✔ forcats 0.3.0
## ── Conflicts ──────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ✖ dplyr::select() masks MASS::select()
cor_matrix<-cor(Boston)  %>% round(digits=2)
corrplot(cor_matrix, type="upper", cl.pos = "b",tl.pos = "d",tl.cex = 0.6  )

In the graph, the blue colour represents positive correlation between variables while the red rpresents the negatives. The darker the colour and the bigger the ball, the stronger the correlation is. For example, the big blue ball between “rad” and “tax” tells that there is a strong correlation between access to highways and property tax rate.

Now we’ll standardise the data

boston_scaled <- scale(Boston)
summary(boston_scaled)
##       crim                 zn               indus        
##  Min.   :-0.419367   Min.   :-0.48724   Min.   :-1.5563  
##  1st Qu.:-0.410563   1st Qu.:-0.48724   1st Qu.:-0.8668  
##  Median :-0.390280   Median :-0.48724   Median :-0.2109  
##  Mean   : 0.000000   Mean   : 0.00000   Mean   : 0.0000  
##  3rd Qu.: 0.007389   3rd Qu.: 0.04872   3rd Qu.: 1.0150  
##  Max.   : 9.924110   Max.   : 3.80047   Max.   : 2.4202  
##       chas              nox                rm               age         
##  Min.   :-0.2723   Min.   :-1.4644   Min.   :-3.8764   Min.   :-2.3331  
##  1st Qu.:-0.2723   1st Qu.:-0.9121   1st Qu.:-0.5681   1st Qu.:-0.8366  
##  Median :-0.2723   Median :-0.1441   Median :-0.1084   Median : 0.3171  
##  Mean   : 0.0000   Mean   : 0.0000   Mean   : 0.0000   Mean   : 0.0000  
##  3rd Qu.:-0.2723   3rd Qu.: 0.5981   3rd Qu.: 0.4823   3rd Qu.: 0.9059  
##  Max.   : 3.6648   Max.   : 2.7296   Max.   : 3.5515   Max.   : 1.1164  
##       dis               rad               tax             ptratio       
##  Min.   :-1.2658   Min.   :-0.9819   Min.   :-1.3127   Min.   :-2.7047  
##  1st Qu.:-0.8049   1st Qu.:-0.6373   1st Qu.:-0.7668   1st Qu.:-0.4876  
##  Median :-0.2790   Median :-0.5225   Median :-0.4642   Median : 0.2746  
##  Mean   : 0.0000   Mean   : 0.0000   Mean   : 0.0000   Mean   : 0.0000  
##  3rd Qu.: 0.6617   3rd Qu.: 1.6596   3rd Qu.: 1.5294   3rd Qu.: 0.8058  
##  Max.   : 3.9566   Max.   : 1.6596   Max.   : 1.7964   Max.   : 1.6372  
##      black             lstat              medv        
##  Min.   :-3.9033   Min.   :-1.5296   Min.   :-1.9063  
##  1st Qu.: 0.2049   1st Qu.:-0.7986   1st Qu.:-0.5989  
##  Median : 0.3808   Median :-0.1811   Median :-0.1449  
##  Mean   : 0.0000   Mean   : 0.0000   Mean   : 0.0000  
##  3rd Qu.: 0.4332   3rd Qu.: 0.6024   3rd Qu.: 0.2683  
##  Max.   : 0.4406   Max.   : 3.5453   Max.   : 2.9865

Now all the observations are using the same scale. Making assumptions about the summary for example is meaningful.

Then we must turn “boston_scaled” back into a data.frame

boston_scaled <- as.data.frame(boston_scaled)

These lines give us the cathegorical variable “crime”

bins <- quantile(boston_scaled$crim)
crime <- cut(boston_scaled$crim, breaks = bins, include.lowest = TRUE, labels = c("low", "med_low", "med_high", "high"))

And these replace the old variable “crim” with the cathegorical crime

boston_scaled <- dplyr::select(boston_scaled, -crim)
boston_scaled <- data.frame(boston_scaled, crime)

Then we divide the data to train with 80% of the data and test with 20% of the data.

n <- nrow(boston_scaled)
ind <- sample(n,  size = n * 0.8)
train <- boston_scaled[ind,]
test <- boston_scaled[-ind,]
  1. Because the data has now been cathegorised into separate sets for training and testing, we can use the training-part for linear discriminant analysis, where crime rate will be predicted by all of the other variables.
lda.fit <- lda(crime ~ ., data = train)
lda.arrows <- function(x, myscale = 1, arrow_heads = 0.1, color = "red", tex = 0.75, choices = c(1,2)){
  heads <- coef(x)
  arrows(x0 = 0, y0 = 0, 
         x1 = myscale * heads[,choices[1]], 
         y1 = myscale * heads[,choices[2]], col=color, length = arrow_heads)
  text(myscale * heads[,choices], labels = row.names(heads), 
       cex = tex, col=color, pos=3)
}

classes <- as.numeric(train$crime)

plot(lda.fit, dimen = 2, col=classes)
lda.arrows(lda.fit, myscale = 2)

Looking at the bi-plot, it’s clear that the “rad”-variable acts (on its own) as a predictor of “high crime rate” in the Boston data. The other 12 variables are associated with low, medium low and medium high rates of crime. The grouping based on these 12 variables is quite vague and it is difficult to see whether any of the variables can accurately/adequately sort the associated observations.

crime_cat<-test$crime
test<-dplyr::select(test, -crime)
lda.pred<-predict(lda.fit, newdata = test)
table(correct = crime_cat, predicted = lda.pred$class)
##           predicted
## correct    low med_low med_high high
##   low       17       8        1    0
##   med_low    8      16        1    0
##   med_high   1      11       15    1
##   high       0       0        0   23

The amount of correct cases and of predicted cases for each of the cathegories (low, med_low, med_high, high) varies between every sample matrix. The change is to be expected as the sets we have created have been randomly classified. There is much less variation between predictions for the “high” class than there is in the predictions of the others.

  1. Before we practice K-means clustering, we should reload the Boston data, scale it, and afterwards measure the distances between the observations.
data(Boston)
boston_scaled1<-as.data.frame(scale(Boston))
dist_eu<-dist(boston_scaled1)
summary(dist_eu)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.1343  3.4625  4.8241  4.9111  6.1863 14.3970
head(boston_scaled1)
##         crim         zn      indus       chas        nox        rm
## 1 -0.4193669  0.2845483 -1.2866362 -0.2723291 -0.1440749 0.4132629
## 2 -0.4169267 -0.4872402 -0.5927944 -0.2723291 -0.7395304 0.1940824
## 3 -0.4169290 -0.4872402 -0.5927944 -0.2723291 -0.7395304 1.2814456
## 4 -0.4163384 -0.4872402 -1.3055857 -0.2723291 -0.8344581 1.0152978
## 5 -0.4120741 -0.4872402 -1.3055857 -0.2723291 -0.8344581 1.2273620
## 6 -0.4166314 -0.4872402 -1.3055857 -0.2723291 -0.8344581 0.2068916
##          age      dis        rad        tax    ptratio     black
## 1 -0.1198948 0.140075 -0.9818712 -0.6659492 -1.4575580 0.4406159
## 2  0.3668034 0.556609 -0.8670245 -0.9863534 -0.3027945 0.4406159
## 3 -0.2655490 0.556609 -0.8670245 -0.9863534 -0.3027945 0.3960351
## 4 -0.8090878 1.076671 -0.7521778 -1.1050216  0.1129203 0.4157514
## 5 -0.5106743 1.076671 -0.7521778 -1.1050216  0.1129203 0.4406159
## 6 -0.3508100 1.076671 -0.7521778 -1.1050216  0.1129203 0.4101651
##        lstat       medv
## 1 -1.0744990  0.1595278
## 2 -0.4919525 -0.1014239
## 3 -1.2075324  1.3229375
## 4 -1.3601708  1.1815886
## 5 -1.0254866  1.4860323
## 6 -1.0422909  0.6705582

The scaled Boston data will now be used for K-means clustering. It isn’t trivial (in many cases) to investigate on the number of clusters that can classify the data. Therefore, we need to first randomize the usage of a certain number of clusters.

First let’s start with a random number cluster. Let us choose k=4 and apply k-means on the data.

kmm = kmeans(boston_scaled1,6,nstart = 50 ,iter.max = 15) 

The elbow method is one good technique using which we can estimate the number of clusters.

library(ggplot2)
set.seed(1234)
k.max <- 15
data <- boston_scaled1
wss <- sapply(1:k.max, 
              function(k){kmeans(data, k)$tot.withinss})
qplot(1:k.max, wss, geom = c("point", "line"), span = 0.2,
     xlab="Number of clusters K",
     ylab="Total within-clusters sum of squares")
## Warning: Ignoring unknown parameters: span

## Warning: Ignoring unknown parameters: span

The elbow plot seems to indicate that we may not find more than two clear clusters but it’s good to confirm predictions using another method because there is no shortage of methods for analyses like these. Let’s try the “NbClust”- package.

library(NbClust)
nb <- NbClust(boston_scaled1, diss=NULL, distance = "euclidean", 
              min.nc=2, max.nc=5, method = "kmeans", 
              index = "all", alphaBeale = 0.1)

## *** : The Hubert index is a graphical method of determining the number of clusters.
##                 In the plot of Hubert index, we seek a significant knee that corresponds to a 
##                 significant increase of the value of the measure i.e the significant peak in Hubert
##                 index second differences plot. 
## 

## *** : The D index is a graphical method of determining the number of clusters. 
##                 In the plot of D index, we seek a significant knee (the significant peak in Dindex
##                 second differences plot) that corresponds to a significant increase of the value of
##                 the measure. 
##  
## ******************************************************************* 
## * Among all indices:                                                
## * 12 proposed 2 as the best number of clusters 
## * 6 proposed 3 as the best number of clusters 
## * 3 proposed 4 as the best number of clusters 
## * 3 proposed 5 as the best number of clusters 
## 
##                    ***** Conclusion *****                            
##  
## * According to the majority rule, the best number of clusters is  2 
##  
##  
## *******************************************************************
hist(nb$Best.nc[1,], breaks = max(na.omit(nb$Best.nc[1,])))

Now, it’s easier to see that the data is described better with two clusters. With that, we should run the k-means algorithm again.

km_final = kmeans(boston_scaled1, centers = 2) 
pairs(boston_scaled1[3:9], col=km_final$cluster)

The clusters in the above plot are divided into two groups and outlined using the colors red and black. Some of the pairs are better grouped than other ones in the plot. One of the important observations can be made with the “chas”-variable where the observations in all of the pairs formed by it are wrongly clustered. Still, clusters formed by the “rad” variable are better separated.

Bonus:

Now, we will use a randomly selected cluster number (k=6) and perform LDA. We shall follow the the basic steps of scaling and distance calculation. Afterwards, we will find out how the biplot looks (of the whole data set) as we try to group it into six different categories.

boston_scaled2<-as.data.frame(scale(Boston))
head(boston_scaled2)
##         crim         zn      indus       chas        nox        rm
## 1 -0.4193669  0.2845483 -1.2866362 -0.2723291 -0.1440749 0.4132629
## 2 -0.4169267 -0.4872402 -0.5927944 -0.2723291 -0.7395304 0.1940824
## 3 -0.4169290 -0.4872402 -0.5927944 -0.2723291 -0.7395304 1.2814456
## 4 -0.4163384 -0.4872402 -1.3055857 -0.2723291 -0.8344581 1.0152978
## 5 -0.4120741 -0.4872402 -1.3055857 -0.2723291 -0.8344581 1.2273620
## 6 -0.4166314 -0.4872402 -1.3055857 -0.2723291 -0.8344581 0.2068916
##          age      dis        rad        tax    ptratio     black
## 1 -0.1198948 0.140075 -0.9818712 -0.6659492 -1.4575580 0.4406159
## 2  0.3668034 0.556609 -0.8670245 -0.9863534 -0.3027945 0.4406159
## 3 -0.2655490 0.556609 -0.8670245 -0.9863534 -0.3027945 0.3960351
## 4 -0.8090878 1.076671 -0.7521778 -1.1050216  0.1129203 0.4157514
## 5 -0.5106743 1.076671 -0.7521778 -1.1050216  0.1129203 0.4406159
## 6 -0.3508100 1.076671 -0.7521778 -1.1050216  0.1129203 0.4101651
##        lstat       medv
## 1 -1.0744990  0.1595278
## 2 -0.4919525 -0.1014239
## 3 -1.2075324  1.3229375
## 4 -1.3601708  1.1815886
## 5 -1.0254866  1.4860323
## 6 -1.0422909  0.6705582
set.seed(1234)
km_bs2<-kmeans(dist_eu, centers = 6)
head(km_bs2)
## $cluster
##   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18 
##   6   6   6   6   6   6   6   4   4   6   4   6   6   4   4   4   6   4 
##  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36 
##   4   4   4   4   4   4   4   4   4   4   4   4   4   4   4   4   4   4 
##  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54 
##   4   6   6   1   1   6   6   6   6   6   6   4   4   6   6   6   6   6 
##  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72 
##   1   1   1   1   6   6   6   6   6   6   1   1   1   6   6   6   6   6 
##  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90 
##   6   6   6   6   4   4   4   6   6   6   6   6   6   6   6   6   6   6 
##  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 
##   6   6   6   6   4   6   6   3   3   6   4   4   4   4   4   4   4   4 
## 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 
##   4   4   4   4   4   4   4   4   4   4   4   4   4   4   4   2   4   4 
## 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 
##   2   2   2   2   4   4   4   4   2   2   2   2   2   2   2   2   5   2 
## 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 
##   5   5   5   5   5   2   2   2   5   2   5   5   5   3   4   2   3   3 
## 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 
##   3   3   4   4   3   4   4   4   4   4   4   4   4   6   6   6   6   6 
## 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 
##   3   6   6   6   4   6   3   6   6   1   1   1   1   1   1   1   1   1 
## 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 
##   1   1   1   1   1   1   1   6   6   4   3   3   3   3   3   6   4   6 
## 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 
##   3   4   3   3   3   3   3   6   3   3   3   6   3   6   4   6   3   3 
## 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 
##   3   4   3   6   6   6   6   6   6   6   6   6   6   6   6   6   6   6 
## 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 
##   1   1   1   1   1   3   3   3   3   3   3   3   3   3   3   3   3   3 
## 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 
##   6   6   6   3   3   6   3   3   6   6   3   6   3   1   1   1   1   6 
## 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 
##   6   1   1   1   1   6   6   6   6   6   1   1   1   6   6   6   6   6 
## 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 
##   6   6   4   4   4   4   4   4   4   4   4   4   4   4   6   6   6   4 
## 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 
##   6   6   6   6   6   6   6   6   6   6   6   6   6   6   6   6   6   1 
## 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 
##   6   6   1   6   6   1   1   1   6   1   1   1   1   1   5   5   5   2 
## 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 
##   2   2   2   5   5   5   2   5   5   5   5   2   5   5   5   2   2   2 
## 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 
##   2   2   5   2   2   2   5   5   5   5   5   2   2   2   2   2   2   2 
## 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 
##   2   2   5   2   5   2   2   2   5   5   5   2   2   2   5   5   5   5 
## 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 
##   5   5   5   5   5   5   2   2   2   5   5   5   5   5   5   5   2   5 
## 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 
##   2   2   5   5   5   5   5   2   2   2   2   2   2   5   2   2   2   2 
## 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 
##   5   2   2   2   5   5   5   5   2   2   2   2   2   2   2   2   5   2 
## 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 
##   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2   2 
## 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 
##   2   2   2   2   5   2   2   4   4   4   4   4   4   4   4   4   4   4 
## 505 506 
##   4   4 
## 
## $centers
##          1        2        3        4        5        6        7        8
## 1 3.989644 4.556297 4.216580 3.977768 4.072917 4.089124 4.248097 4.850842
## 2 5.635860 5.015922 5.810840 6.243394 6.219170 5.797678 5.007134 5.045384
## 3 4.115845 4.367908 3.914214 4.415556 4.277226 4.521520 4.462950 4.591271
## 4 3.322873 2.419949 3.555546 3.901515 3.917887 3.259432 2.872770 3.145128
## 5 7.347551 6.917018 7.668887 8.029178 8.008552 7.594726 6.746593 6.719663
## 6 2.552963 2.191615 2.547985 2.481257 2.636215 2.126035 2.463163 3.260455
##          9       10       11       12       13       14       15       16
## 1 6.023239 4.730761 5.085827 4.546510 4.256435 5.022876 5.346690 5.064489
## 2 5.275376 5.034209 5.024306 5.008656 5.191566 4.483294 4.239085 4.500312
## 3 5.861940 4.897185 5.053174 4.724166 4.806196 5.041859 5.037049 5.123212
## 4 3.802664 3.078288 3.240106 2.958259 3.171899 2.294340 2.083575 2.330854
## 5 6.637733 6.672022 6.656885 6.725987 6.831291 6.522547 6.271019 6.514117
## 6 4.420281 3.050288 3.460627 2.800817 2.548810 2.498158 2.847417 2.519525
##         17       18       19       20       21       22       23       24
## 1 4.839017 5.494447 5.410418 5.409972 6.301722 5.559564 5.849309 6.119225
## 2 4.932293 4.118743 4.699219 4.231080 4.140866 4.107180 4.064205 4.123917
## 3 5.188031 5.159236 5.556072 5.185846 5.777782 5.080391 5.333884 5.590056
## 4 2.926372 2.006490 2.829410 2.073005 2.478201 1.996680 2.200197 2.363123
## 5 6.848068 6.136584 6.246617 6.243108 5.944153 6.154788 6.070741 6.047729
## 6 2.477710 2.972866 3.035484 2.815474 3.883785 3.047242 3.413583 3.706860
##         25       26       27       28       29       30       31       32
## 1 5.776453 5.909337 5.645826 5.792679 5.463721 5.291108 6.251560 5.790675
## 2 4.125236 4.229138 4.173627 4.154204 4.209655 4.253839 4.190000 4.132815
## 3 5.355804 5.648491 5.331440 5.423799 4.956368 4.757484 5.818922 5.290357
## 4 2.152358 2.399737 2.130704 2.313981 2.194705 2.226566 2.563711 2.185395
## 5 6.124494 5.850285 6.119300 5.848617 6.281408 6.323214 5.926407 6.111869
## 6 3.317906 3.492059 3.174430 3.407128 3.072595 2.917289 3.883866 3.341829
##         33       34       35       36       37       38       39       40
## 1 6.577978 6.113220 6.286376 5.003424 4.975828 4.672432 4.567581 2.437628
## 2 4.543962 4.083659 4.244460 4.504907 4.504214 4.851253 4.995628 6.988766
## 3 6.168152 5.623677 5.717537 4.728770 4.767845 4.847078 4.787796 5.456166
## 4 3.295133 2.297075 2.760000 2.036929 2.052171 2.484306 2.720323 5.019539
## 5 5.702765 5.899302 5.635547 6.472198 6.389736 6.751702 6.860251 8.586641
## 6 4.437132 3.655982 4.014459 2.356225 2.324457 2.085109 2.100542 3.469146
##         41       42       43       44       45       46       47       48
## 1 2.550075 4.003727 4.101822 4.105741 4.205545 4.493890 4.535762 5.127133
## 2 7.347068 6.266063 6.066725 6.010008 5.405380 5.401641 5.323536 4.969192
## 3 5.469978 4.947438 5.088076 5.079073 4.810066 5.080046 5.057556 5.071546
## 4 5.447668 4.089165 3.798403 3.739937 2.899376 2.938610 2.889613 2.590240
## 5 8.944151 7.985202 7.757987 7.727039 7.185569 7.146905 7.056687 6.715830
## 6 3.806323 2.464106 2.277093 2.245886 1.890630 2.124631 2.187826 2.870058
##         49       50       51       52       53       54       55       56
## 1 6.354068 4.788056 3.687296 3.635669 3.127248 3.365371 3.768251 2.573205
## 2 5.425549 5.185207 5.660587 5.607665 6.251113 6.093472 6.228695 8.172561
## 3 6.206363 5.152123 5.037840 4.798345 4.875844 5.098446 6.488456 6.248718
## 4 3.649819 2.729138 3.311553 3.194530 3.999725 3.806354 4.738612 6.360064
## 5 6.857506 6.903606 7.327416 7.333311 7.954340 7.750576 7.846534 9.656599
## 6 4.374890 2.484987 2.216591 2.155992 2.202966 2.192392 4.011314 4.620562
##         57       58       59       60       61       62       63       64
## 1 2.435993 2.586150 3.455264 3.762957 4.163099 4.634886 3.692547 3.384146
## 2 7.625711 8.169946 5.852530 5.357849 5.193164 4.988228 5.388941 5.749506
## 3 6.314081 6.255593 5.396948 5.291164 5.423722 5.411219 4.967901 5.080093
## 4 5.728217 6.380166 3.850185 3.257986 3.128914 3.007457 3.306577 3.782189
## 5 9.093653 9.562610 7.619436 7.182935 6.981514 6.757826 7.282673 7.580278
## 6 4.138053 4.788808 2.369128 2.238707 2.577586 3.001430 2.348247 2.423646
##         65       66       67       68       69       70       71       72
## 1 3.572872 2.365488 2.854471 3.828722 4.245479 3.861492 4.311560 4.482338
## 2 6.803815 7.202476 6.871459 5.702754 5.382884 5.506994 5.679697 5.332385
## 3 5.070095 5.920134 6.075955 5.331567 5.513971 5.232351 5.172823 5.258275
## 4 4.571372 5.363377 5.039822 3.540862 3.214330 3.286807 3.670384 3.233668
## 5 8.474576 8.706790 8.325184 7.481800 7.133931 7.317062 7.509722 7.139492
## 6 3.099810 3.755717 3.762213 2.164752 2.377335 2.067120 2.395258 2.279879
##         73       74       75       76       77       78       79       80
## 1 4.423047 4.374894 4.565665 4.571969 4.993178 4.715682 4.645174 4.703818
## 2 5.670343 5.628241 5.253844 4.504533 4.080734 4.392771 4.369389 4.613917
## 3 5.331200 5.256931 5.138078 4.739219 4.676271 4.796607 4.781211 5.037161
## 4 3.633211 3.612120 3.532216 2.554765 2.115305 2.435091 2.406743 2.698489
## 5 7.496987 7.426016 7.172186 6.550720 6.164051 6.445026 6.421550 6.621032
## 6 2.419650 2.395619 2.582255 2.208724 2.569263 2.284706 2.281898 2.322846
##         81       82       83       84       85       86       87       88
## 1 3.228722 3.647245 3.352955 3.510806 4.214393 4.216222 4.470996 4.539526
## 2 5.833680 5.345002 5.671433 5.439196 5.298921 5.378578 5.181960 5.119600
## 3 4.611003 4.507704 4.824876 4.799211 4.493640 4.250144 4.736784 4.543074
## 4 3.593223 2.978716 3.362220 3.049922 2.723815 2.845202 2.603436 2.477017
## 5 7.679009 7.247432 7.495607 7.269305 7.155841 7.257393 6.986917 6.981295
## 6 2.077143 2.128207 1.941076 1.906614 1.839655 1.960338 2.004413 2.011357
##         89       90       91       92       93       94       95       96
## 1 4.787782 4.431266 4.656816 4.754404 4.105175 4.001644 4.521147 4.347592
## 2 5.260876 5.460377 5.023131 4.997348 4.772459 5.169144 4.479851 5.437460
## 3 4.086432 3.906040 4.252949 4.267811 4.510455 4.766874 4.611235 4.143402
## 4 2.894806 3.107514 2.443156 2.419531 2.751041 3.222217 2.448424 2.937590
## 5 7.155386 7.332941 6.878036 6.862533 6.774331 7.083584 6.505216 7.188899
## 6 2.659893 2.401307 2.216247 2.322228 2.415933 2.468939 2.704529 2.182013
##         97       98       99      100      101      102      103      104
## 1 4.715695 4.926015 4.640776 4.444450 5.282563 5.152315 6.572203 5.683531
## 2 5.051112 6.412041 6.764467 5.837829 4.205067 4.305317 5.036975 3.815398
## 3 4.508034 3.931800 4.158120 3.883013 4.489959 4.495810 6.000236 5.001289
## 4 2.400338 4.464342 4.810546 3.603211 2.414290 2.493991 3.966604 1.972705
## 5 6.868421 8.203118 8.491487 7.681807 6.393702 6.492260 5.811685 5.987192
## 6 2.261612 3.692387 3.630574 2.739459 2.966666 2.843788 4.692793 3.172095
##        105      106      107      108      109      110      111      112
## 1 5.724543 6.103378 6.104999 5.770964 5.777602 5.809233 5.260548 5.174233
## 2 3.840428 3.789013 3.785737 3.801714 3.887880 3.778476 4.058712 3.895295
## 3 4.956142 5.253274 5.307506 4.990050 4.894350 5.027813 4.918935 4.183520
## 4 2.022137 2.164155 2.196416 2.023648 2.172750 2.042266 2.184470 2.238546
## 5 6.014221 5.881611 5.856170 5.944714 6.084653 5.930743 6.185964 6.069764
## 6 3.223448 3.618628 3.631351 3.259679 3.351457 3.335422 2.743048 2.868558
##        113      114      115      116      117      118      119      120
## 1 5.795991 5.778504 5.457332 5.719642 5.202323 5.373780 5.497713 5.357061
## 2 3.601847 3.596459 3.722199 3.590667 3.748787 3.744213 3.671311 3.776235
## 3 4.819193 4.774286 4.530960 4.818453 4.451377 4.589012 4.741708 4.798190
## 4 2.075218 2.106269 2.052459 2.053031 1.971584 1.988655 2.048517 2.045794
## 5 5.667421 5.680606 5.851170 5.493919 5.878062 5.869090 5.544023 5.809181
## 6 3.375466 3.392521 3.026294 3.301736 2.747953 2.915253 3.063432 2.869590
##        121      122      123      124      125      126      127      128
## 1 6.426088 6.565457 6.806695 7.305465 6.897705 6.650747 7.533959 7.099802
## 2 4.261019 4.162980 4.128457 4.247333 4.123875 4.163650 4.355189 3.161437
## 3 5.427653 5.424854 5.565025 6.069215 5.659762 5.427403 6.344535 5.999576
## 4 2.985164 2.938368 3.039074 3.475730 3.062302 2.973639 3.677551 2.962007
## 5 6.237519 6.139760 6.064278 6.001360 6.051491 6.152869 5.974765 5.445330
## 6 4.116775 4.252645 4.510005 5.058229 4.583383 4.343081 5.287399 4.735059
##        129      130      131      132      133      134      135      136
## 1 6.875876 7.154803 6.726119 6.686918 6.596530 6.821369 7.166802 6.870993
## 2 3.183589 3.174651 3.265601 3.234532 3.348169 3.162883 3.338913 3.134950
## 3 5.627423 6.120486 5.509731 5.516882 5.382470 5.779404 6.139554 5.674601
## 4 2.931268 3.021401 2.885217 2.835481 2.871725 2.806058 3.188140 2.903821
## 5 5.604137 5.425648 5.688097 5.652880 5.721190 5.497188 5.035538 5.535608
## 6 4.590233 4.791289 4.456575 4.402201 4.350142 4.479053 4.894039 4.582035
##        137      138      139      140      141      142      143      144
## 1 6.929533 6.859261 7.327005 7.036231 7.324311 8.387851 9.118028 8.148386
## 2 3.098547 3.195797 3.203702 3.121999 3.270140 4.203114 6.057048 4.491078
## 3 5.819167 5.632765 6.197877 5.809014 6.167568 7.327389 6.736697 6.601594
## 4 2.859060 2.928458 3.172007 2.969872 3.289011 4.421385 6.210476 4.719098
## 5 5.406565 5.610438 5.411571 5.483828 5.434774 5.732297 6.519423 5.705948
## 6 4.585322 4.572210 4.994596 4.721431 5.047669 6.196553 7.427033 6.200054
##        145      146      147      148      149      150      151      152
## 1 8.591160 8.420611 8.051529 8.485530 8.220414 7.812856 7.329573 7.603008
## 2 4.881773 4.956580 4.786268 4.850486 4.658853 4.298230 4.279168 4.390872
## 3 7.209721 6.881696 6.562636 7.091389 6.756783 6.281936 5.599987 6.029305
## 4 5.120965 5.221320 4.864032 5.058645 4.839584 4.425501 4.201583 4.325365
## 5 5.882920 5.395652 5.350043 5.860027 5.668932 5.539694 5.844264 5.733672
## 6 6.628290 6.634143 6.205886 6.539074 6.293195 5.851136 5.439102 5.651936
##        153      154      155      156      157      158      159      160
## 1 8.622664 7.648725 8.381752 8.889137 8.425203 6.168678 6.265700 7.165808
## 2 6.067192 4.403229 5.843835 6.536516 5.328492 5.218020 4.320602 4.558378
## 3 6.369979 6.052779 5.844207 6.703763 7.158351 4.234387 4.756091 5.368031
## 4 5.967163 4.417624 5.805631 6.566625 5.400744 4.276378 3.305864 4.351927
## 5 6.541819 5.446370 6.344801 6.334474 5.503366 6.942094 6.074535 6.178603
## 6 6.952748 5.752673 6.793409 7.450863 6.650053 4.652464 4.273222 5.383270
##        161      162      163      164      165      166      167      168
## 1 7.231434 6.383671 7.606315 7.711715 6.150603 6.283786 6.542030 6.239898
## 2 5.940257 6.088162 7.394089 7.646620 4.086328 4.360674 6.228342 4.356613
## 3 4.605274 4.398804 4.791045 4.937649 4.851661 4.926498 4.456582 5.095670
## 4 5.239834 5.208814 6.712875 6.998166 3.062315 3.452702 5.427142 3.432231
## 5 6.821006 7.745103 8.432676 8.695086 5.936568 5.663492 7.854149 5.576630
## 6 5.752473 5.237762 6.745173 6.961257 4.080738 4.385762 5.475612 4.315636
##        169      170      171      172      173      174      175      176
## 1 6.213385 6.133807 6.433082 6.312035 5.454412 4.962647 4.941506 4.309193
## 2 4.170734 4.100748 4.054129 4.025673 4.699883 4.808037 4.816591 5.496225
## 3 4.728033 4.677209 5.202442 5.015219 4.676351 4.091021 4.407110 4.153032
## 4 3.234454 3.142836 3.181914 3.077576 2.488721 2.512347 2.447970 3.326034
## 5 5.730715 5.794348 5.516106 5.715890 6.426784 6.668081 6.607389 7.275149
## 6 4.254128 4.150282 4.374444 4.230784 3.104965 2.654763 2.534686 2.342553
##        177      178      179      180      181      182      183      184
## 1 4.520962 4.655885 4.649899 4.604653 5.132343 4.814462 5.087352 5.054530
## 2 5.015596 4.976181 5.157347 5.945635 6.198433 5.587189 5.931557 5.543818
## 3 4.411335 4.095254 3.737891 3.879091 3.800673 4.190561 3.860567 4.061937
## 4 2.658053 2.616342 2.975519 3.642452 4.178165 3.143454 3.744498 3.144853
## 5 6.792977 6.830833 7.010189 7.720425 7.949502 7.318332 7.703218 7.337983
## 6 2.175426 2.365924 2.589714 2.810682 3.656914 2.701373 3.342620 2.979474
##        185      186      187      188      189      190      191      192
## 1 5.360158 4.777155 5.085672 3.049814 2.837691 2.892236 2.592917 2.487691
## 2 5.146074 5.258702 6.977902 6.090983 6.253786 6.421824 6.840347 6.509686
## 3 4.706625 4.276810 4.103340 4.369622 4.665779 4.360736 4.840840 4.814221
## 4 2.617485 2.667473 5.069928 4.220068 4.355866 4.608931 5.027524 4.620020
## 5 6.823279 6.988966 8.637738 7.764729 7.876360 8.097468 8.409214 8.135143
## 6 3.009695 2.461779 4.108449 2.947084 2.866184 3.171421 3.299804 2.939362
##        193      194      195       196      197      198      199      200
## 1 2.626002 2.323019 2.285881  3.495329 2.818135 2.825122 2.840680 2.451539
## 2 6.916387 7.350478 7.173909  8.592641 8.185358 7.919777 8.103044 7.965488
## 3 4.786382 5.315615 5.265629  5.625695 5.786297 5.784978 5.720384 6.255528
## 4 5.115810 5.261122 5.038340  6.858470 6.362933 6.100498 6.288002 6.311681
## 5 8.533158 8.873489 8.672208 10.009282 9.580192 9.208468 9.481059 9.444290
## 6 3.385297 3.423873 3.258558  5.286849 4.731058 4.582926 4.715512 4.639590
##        201      202      203       204       205      206      207
## 1 2.456624 2.615509 2.868195  3.538131  3.737246 4.677119 4.523642
## 2 7.969849 7.156198 8.271244  8.640337  8.822374 4.966944 4.612421
## 3 6.272606 5.771920 5.739854  5.855113  5.957838 4.945805 4.407545
## 4 6.329487 5.273529 6.554190  6.965429  7.174721 2.820461 2.266758
## 5 9.430213 8.587107 9.723775 10.042167 10.216692 6.837520 6.613955
## 6 4.653597 3.907488 4.866644  5.491799  5.693985 2.252863 1.996460
##        208      209      210      211      212      213      214      215
## 1 5.173003 6.173648 7.246427 6.672900 7.168488 6.358530 4.424781 5.994199
## 2 4.338029 5.951508 5.923358 5.785418 5.899356 5.931043 4.957469 5.447417
## 3 4.839209 4.297639 5.214301 4.486356 5.179802 4.522080 4.441468 6.128544
## 4 2.088170 4.501917 4.748828 4.456045 4.719108 4.521710 2.774437 3.942573
## 5 6.238923 7.056415 6.886396 6.882747 6.859678 7.017952 6.877368 6.804923
## 6 2.684155 4.559083 5.472929 4.942984 5.391736 4.669469 2.088834 4.075614
##        216      217      218      219      220      221      222      223
## 1 4.533967 6.461391 5.090497 6.968673 6.593520 6.320911 6.799719 6.130295
## 2 4.734048 5.887167 4.502200 5.707295 5.831456 6.068344 5.809474 6.083430
## 3 4.493721 4.333352 3.927803 4.474244 4.098632 3.855927 4.507648 3.793452
## 4 2.431159 4.642940 2.604000 4.619602 4.623502 4.781149 4.654611 4.752233
## 5 6.701716 6.923664 6.481639 6.712071 6.932306 7.216588 6.814993 7.226735
## 6 2.008161 4.833935 2.937343 5.253528 4.990749 4.858718 5.140070 4.702050
##        224      225      226      227      228      229      230      231
## 1 4.738585 5.386965 5.891695 5.165618 4.738937 4.794451 4.323631 4.757661
## 2 4.706017 6.297753 6.888318 5.848384 4.984604 6.583434 5.480585 4.442431
## 3 3.859178 3.856074 4.287951 3.761622 3.704484 4.327344 4.344291 4.345763
## 4 2.632171 4.857703 5.604564 4.291528 3.086868 5.025870 3.556647 2.180368
## 5 6.676587 8.061548 8.562013 7.691942 6.882629 8.267586 7.279603 6.313200
## 6 2.510992 4.285144 5.053107 3.807224 2.766869 3.866941 2.455648 2.274652
##        232      233      234      235      236      237      238      239
## 1 4.653852 5.135020 5.281054 5.952219 4.649091 6.018095 4.490512 2.932965
## 2 5.189298 6.314557 6.527581 6.182940 4.494536 6.049817 5.234441 6.100275
## 3 3.705792 3.899503 3.957570 3.819634 4.306913 3.896708 3.743105 4.916380
## 4 3.349510 4.826196 5.081229 4.795798 2.237307 4.663958 3.356024 4.006857
## 5 7.086045 8.097837 8.247294 7.256051 6.371138 7.184499 7.164135 7.763565
## 6 2.845373 4.094662 4.348568 4.582063 2.164414 4.571565 2.701412 2.261099
##        240      241      242      243      244      245      246      247
## 1 2.956836 3.179208 3.559831 3.174838 2.972611 4.361124 4.499702 3.449697
## 2 5.782692 5.644636 5.418724 5.676824 6.431679 5.293119 5.282827 5.730382
## 3 4.609977 4.554218 4.836874 4.812866 5.251961 5.595467 5.698876 5.306870
## 4 3.612081 3.523994 3.199172 3.505714 4.402069 3.307803 3.374542 3.724642
## 5 7.513168 7.401734 7.139957 7.340494 8.034419 6.985702 6.964082 7.498675
## 6 2.096391 2.294939 2.317889 2.233775 2.546385 2.843542 3.010876 2.298688
##        248      249      250      251      252      253      254      255
## 1 3.980918 3.426770 3.241080 3.321813 3.366958 3.347543 4.117622 2.565061
## 2 5.332551 5.535635 6.098106 6.038428 6.187201 6.732703 7.679236 7.519106
## 3 5.197006 5.027748 5.230422 5.313640 5.406880 5.560045 5.671848 6.347835
## 4 3.315715 3.504649 4.188133 4.105072 4.276291 4.932310 6.124355 5.596288
## 5 7.123772 7.327359 7.884487 7.824608 7.913195 8.440374 9.349847 8.962012
## 6 2.612063 2.227342 2.472500 2.394111 2.529107 3.107181 4.463447 4.036629
##        256      257      258      259      260      261      262      263
## 1 2.791995 2.848603 6.222798 5.518648 5.417650 5.174118 5.463188 5.971533
## 2 7.592589 8.192506 7.613422 6.131531 5.811603 5.956088 6.518475 7.320962
## 3 6.580192 5.707147 4.551395 3.894518 4.041152 3.826233 3.886648 4.317743
## 4 5.699971 6.403033 6.371304 4.637079 4.211517 4.374564 5.047654 6.017951
## 5 8.992176 9.653615 9.041679 7.629278 7.342798 7.487956 8.005527 8.762238
## 6 4.155292 4.824381 5.880265 4.531389 4.220084 4.147002 4.710711 5.556397
##        264      265      266      267      268      269      270      271
## 1 5.408871 5.364474 5.369503 5.311210 5.468341 4.684862 5.853082 4.111760
## 2 5.873985 6.084410 5.582297 5.691716 7.365150 6.850545 6.292985 5.143047
## 3 3.944671 3.834643 4.846831 4.038079 4.202225 3.938496 4.496815 4.877938
## 4 4.361095 4.543509 3.870860 4.139572 5.912661 5.158425 4.630825 2.685788
## 5 7.399951 7.595295 6.985984 7.167083 8.815364 8.370001 7.374525 6.914144
## 6 4.321892 4.369594 3.895689 4.141040 5.180260 4.218897 4.554789 2.091791
##        272      273      274      275      276      277      278      279
## 1 3.725629 3.921894 5.523364 4.973350 3.058289 4.960332 4.861229 3.070627
## 2 5.736385 5.155769 7.186009 7.238343 6.006291 7.213299 7.355393 5.795132
## 3 4.839362 4.286203 4.148237 4.380952 4.296659 4.210140 4.469765 4.503523
## 4 3.441028 2.665134 5.602045 5.598971 3.877658 5.612713 5.710319 3.612360
## 5 7.520064 7.064234 8.378912 8.386111 7.804129 8.364865 8.493915 7.564951
## 6 2.111547 1.993339 4.916068 4.705346 2.513014 4.779926 4.711343 2.285977
##        280      281      282      283       284      285      286      287
## 1 3.561388 4.216680 3.374750 5.571630  5.408034 2.345212 2.477254 2.927409
## 2 6.491419 7.105591 6.595419 8.219563  9.973467 7.928601 6.930874 7.445534
## 3 4.173615 3.975881 4.184062 4.440886  6.268257 5.936035 5.428512 6.501695
## 4 4.285849 5.167816 4.389736 6.563865  8.344298 6.072569 4.772330 5.471836
## 5 8.122015 8.703650 8.222715 9.258337 10.933893 9.363760 8.450626 8.767961
## 6 2.790991 3.947935 2.795306 5.515391  6.980733 4.422708 3.123714 4.079753
##        288      289      290      291      292      293      294      295
## 1 2.509960 2.585977 2.400932 2.683501 2.813661 2.686863 4.345410 4.479945
## 2 6.413629 6.249971 6.494620 6.930359 7.229010 6.875832 5.592884 5.181463
## 3 5.343188 5.207865 5.287981 5.569837 5.473392 5.650164 4.941731 4.796956
## 4 4.396113 4.214046 4.535171 5.074359 5.432490 5.006978 3.576391 3.058148
## 5 8.041222 7.905277 8.061694 8.582296 8.865102 8.509272 7.358111 6.995131
## 6 2.756566 2.716768 2.843575 3.668080 3.989047 3.608840 2.497209 2.387338
##        296      297      298      299      300      301      302      303
## 1 4.101880 4.215355 4.808009 2.456182 2.336450 2.394242 3.068423 2.941845
## 2 5.702683 5.379947 5.078750 7.315906 7.652372 7.121431 5.575441 5.929574
## 3 4.531097 4.405035 5.064135 5.938158 5.803548 5.507286 4.604003 4.762883
## 4 3.690081 3.281272 3.028002 5.478237 5.872746 5.284133 3.549854 3.969692
## 5 7.527753 7.235927 6.829083 8.722048 9.087048 8.634313 7.337638 7.605560
## 6 2.491650 2.393691 2.750925 3.788908 4.039227 3.734424 2.232083 2.376030
##        304      305      306      307      308      309      310      311
## 1 2.855273 3.436586 3.684046 3.978741 3.854584 4.998677 5.185967 5.719675
## 2 6.336183 6.106407 5.435975 5.842022 5.453779 4.466812 4.127252 4.624290
## 3 4.561650 4.196815 4.266337 4.017975 4.168573 4.202224 4.535816 5.594347
## 4 4.456508 4.073418 3.192729 3.845712 3.261918 2.344549 1.843049 2.847242
## 5 8.039455 7.868780 7.241481 7.658684 7.290961 6.546441 6.168368 6.187983
## 6 2.734380 2.774880 2.361712 3.039054 2.564437 2.631756 2.582365 3.293284
##        312      313      314      315      316      317      318      319
## 1 4.937184 5.460141 5.098426 5.028976 5.293601 5.460000 5.215271 4.838880
## 2 4.467670 4.023815 4.217072 4.259199 4.159874 4.029901 4.115912 4.245101
## 3 4.476328 4.594927 4.348331 4.178642 4.891978 4.889172 4.794276 4.262780
## 4 2.297145 1.850451 1.966400 2.079641 1.938234 1.959365 1.906122 1.969043
## 5 6.476538 6.069256 6.284457 6.344720 6.136907 5.966724 6.078177 6.307673
## 6 2.402724 2.904430 2.574041 2.606905 2.711944 2.970980 2.658070 2.293294
##        320      321      322      323      324      325      326      327
## 1 4.842685 4.449705 4.484974 4.585730 5.057642 4.334264 4.248227 4.277525
## 2 4.240360 4.799353 4.776401 4.757420 4.457601 5.018766 5.526219 5.218292
## 3 4.534455 4.506705 4.537503 4.811214 4.996492 4.590902 4.987239 4.873621
## 4 1.963279 2.473559 2.434921 2.406058 2.072533 2.775066 3.465771 3.042737
## 5 6.250142 6.816256 6.795014 6.731231 6.397846 6.994614 7.395759 7.139104
## 6 2.254385 1.961575 1.975895 2.005309 2.474246 1.958008 2.220200 2.005009
##        328      329      330      331      332      333      334      335
## 1 4.511237 4.336792 4.068778 4.134704 3.513382 3.127529 4.341878 4.382338
## 2 4.796609 5.372181 5.613018 5.389720 5.942590 6.090114 5.485716 5.424178
## 3 4.877258 5.105806 4.900165 4.957900 5.488342 5.279997 5.053555 5.093833
## 4 2.517471 3.305539 3.594198 3.303857 3.752625 3.884973 3.226203 3.160665
## 5 6.725423 7.068932 7.323299 7.087469 7.538669 7.661878 7.331467 7.267954
## 6 2.035908 2.350131 2.312741 2.230762 2.580536 2.403384 2.205917 2.203234
##        336      337      338      339      340      341      342      343
## 1 4.485929 4.729718 4.812037 4.629130 4.744764 4.837628 2.808348 4.362098
## 2 5.347455 5.032342 4.935566 5.124323 4.979263 4.865181 6.823411 5.448631
## 3 5.156767 5.112746 5.110110 5.016265 5.044939 4.987777 4.514441 4.784059
## 4 3.056405 2.647838 2.524309 2.778949 2.590159 2.417256 4.633530 3.331511
## 5 7.189428 6.898354 6.809633 7.000683 6.865025 6.777057 8.446366 7.165257
## 6 2.186727 2.223765 2.322145 2.157595 2.205404 2.271625 3.007511 2.617582
##        344      345      346      347      348      349      350      351
## 1 2.778316 2.366030 4.320697 4.466973 2.400876 2.213242 2.925825 3.077473
## 2 5.684615 6.353501 5.565696 5.487424 7.183736 7.319965 6.755452 6.526367
## 3 4.757585 4.927327 5.421207 5.492314 6.193135 5.934386 5.524385 5.618626
## 4 3.802233 4.548197 3.369890 3.310384 5.476084 5.437402 4.699873 4.404974
## 5 7.461637 8.044999 7.305607 7.150579 8.715944 8.820537 8.437225 8.219455
## 6 2.672462 2.940953 2.423474 2.543259 3.956148 3.799867 3.066109 2.914978
##        352      353       354      355      356      357      358      359
## 1 2.847020 3.254646  3.220675 4.018615 3.810904 8.663013 8.315674 8.225028
## 2 7.254755 7.319860  8.653858 7.691074 7.769223 4.621450 4.715344 4.749805
## 3 6.269580 6.763444  7.013329 7.521812 7.391746 6.500890 6.156007 6.172788
## 4 5.498901 5.585389  6.831393 6.079486 6.140023 5.907878 5.797393 5.786448
## 5 8.766898 8.789968 10.015464 9.117773 9.216143 5.456756 5.735313 5.758167
## 6 3.882617 4.035485  5.152518 4.846552 4.789845 6.995105 6.715094 6.630405
##        360      361      362      363      364      365      366      367
## 1 7.278021 7.215827 7.464845 7.699553 8.598542 8.542707 8.530898 7.799054
## 2 2.467536 2.805217 2.333627 2.769367 4.652258 6.207836 4.624219 2.863464
## 3 6.182375 6.025704 6.270247 6.585418 6.526351 6.398780 7.725367 6.760694
## 4 4.207340 4.344110 4.232657 4.378729 5.817697 6.961379 5.534146 4.394301
## 5 4.964540 5.192113 4.710339 4.977082 5.468166 7.258598 5.920246 4.657637
## 6 5.340790 5.361453 5.509807 5.682415 6.883975 7.392644 6.618984 5.752759
##        368      369      370      371      372      373      374      375
## 1 8.916963 7.876027 8.330037 8.374001 7.563523 8.532946 8.984585 9.736883
## 2 4.770107 4.939445 6.154059 6.280595 4.367286 5.917457 3.722610 4.767839
## 3 8.102215 6.662121 5.980344 5.981912 6.056314 6.266885 7.931335 8.798177
## 4 5.856186 5.544439 6.673537 6.801323 5.253873 6.587324 5.414656 6.304659
## 5 5.030692 6.544359 7.110024 7.285275 6.133890 6.680971 4.907474 5.412285
## 6 7.067897 6.260581 7.113702 7.203297 5.999323 7.191112 6.985946 7.809059
##        376      377      378      379      380       381      382      383
## 1 7.795568 7.924073 7.787937 8.275536 8.137870 12.821812 7.966471 8.185980
## 2 3.171317 2.549903 2.441746 3.030744 2.612679  9.894275 2.535543 2.500835
## 3 6.521129 6.722821 6.526672 7.136095 7.001182 12.116793 6.800516 7.087802
## 4 4.944969 4.652842 4.462833 5.083590 4.746519 11.163729 4.647065 4.555749
## 5 5.207964 4.521828 4.798660 4.679079 4.555128  9.663159 4.661952 4.529605
## 6 6.017927 6.001561 5.834679 6.394230 6.161471 11.755809 6.015300 6.112881
##        384      385      386      387      388      389      390      391
## 1 8.197628 9.349727 8.910330 9.193301 9.152365 8.907678 8.068366 7.677835
## 2 2.535837 4.207220 3.430304 3.965891 3.922688 3.476912 2.460378 2.173913
## 3 7.080988 8.494759 7.900222 8.245243 8.254546 7.913604 7.016902 6.584068
## 4 4.556169 5.912501 5.372451 5.774218 5.768068 5.325687 4.443905 4.162427
## 5 4.555957 4.593328 4.644399 4.813092 4.798740 4.585380 4.568138 4.613924
## 6 6.125147 7.394570 6.913418 7.236737 7.210917 6.892982 5.975128 5.602574
##        392      393      394      395      396      397      398      399
## 1 7.292592 8.487710 7.524344 7.763687 7.641959 7.677186 8.002371 9.767720
## 2 2.226899 2.983346 2.121055 2.265178 2.176869 2.197872 2.365545 4.881189
## 3 6.187448 7.518315 6.415998 6.699030 6.447121 6.503431 6.938797 8.851159
## 4 4.059557 4.886988 4.152838 4.352711 4.260815 4.238695 4.395922 6.683507
## 5 4.690817 4.584419 4.693783 4.560825 4.700448 4.730041 4.591516 5.349991
## 6 5.308181 6.426170 5.489378 5.726631 5.638596 5.653609 5.914268 7.989079
##        400      401      402      403      404      405       406      407
## 1 8.388325 8.804129 8.087911 7.825523 8.542363 9.552186 11.432606 9.054357
## 2 3.040490 3.471798 2.536220 2.216427 3.279024 4.910238  7.595875 3.994384
## 3 7.463474 7.776663 6.969235 6.627020 7.610294 8.716935 10.666205 8.166864
## 4 4.959465 5.497801 4.669753 4.375806 5.225734 6.673070  9.081383 5.594715
## 5 4.478721 4.713832 4.642624 4.544640 4.647198 5.160244  7.453981 4.877537
## 6 6.400821 6.900501 6.095533 5.820693 6.578583 7.840199 10.009989 7.043493
##        408      409      410       411      412      413      414
## 1 7.570396 7.942399 7.792350 10.375746 8.547474 9.825302 8.675535
## 2 2.751697 2.684071 3.512054  6.953620 4.401901 5.499975 4.000683
## 3 6.317911 6.868005 6.505072  9.624185 7.490223 8.978058 7.777474
## 4 4.354104 4.411296 4.984789  8.179599 5.753451 6.786214 5.592512
## 5 4.684219 4.359127 4.498617  6.248943 4.283169 4.939472 4.338544
## 6 5.605718 5.909119 6.091597  9.003486 6.898431 8.111524 6.840670
##         415      416      417      418       419      420      421
## 1 11.272810 9.378378 8.990931 9.186224 12.321200 8.708818 7.649405
## 2  6.897999 4.863694 4.682977 4.396530  8.940339 4.410853 2.275161
## 3 10.507271 8.404166 8.034930 8.321960 11.623093 7.789436 6.412841
## 4  8.419684 6.420781 6.131883 6.083046 10.281934 5.925977 4.353909
## 5  6.006137 4.335355 4.349290 4.150387  7.922425 4.248090 4.384831
## 6  9.673650 7.712449 7.339434 7.393740 11.103741 7.052418 5.696703
##        422      423      424      425      426      427      428      429
## 1 7.665560 7.356701 8.626415 8.441732 9.201143 8.265300 9.461813 8.241034
## 2 2.180745 2.508136 4.580701 4.667841 4.741929 4.569780 5.669296 3.716263
## 3 6.540748 6.403579 7.807594 7.858624 8.314551 7.743199 8.719330 7.368712
## 4 4.220529 4.151550 5.802264 5.736500 6.219861 5.681331 7.081609 5.224531
## 5 4.337641 4.332067 4.287058 4.467816 4.150667 4.462962 5.101391 3.944706
## 6 5.633333 5.359069 6.942560 6.733842 7.490506 6.578878 7.976041 6.437220
##        430      431      432      433      434      435      436      437
## 1 8.696259 7.931573 8.088359 7.540841 8.039230 8.323316 8.488298 8.855936
## 2 4.134503 3.794201 3.973307 3.782250 3.619313 3.721287 3.748221 4.457023
## 3 7.717744 7.082043 7.134695 6.790664 7.058495 7.351287 7.386206 7.874780
## 4 5.654346 5.081922 5.298499 4.904392 5.104864 5.332295 5.460661 5.994414
## 5 4.007002 4.145470 4.267862 4.462911 4.105578 3.959357 3.969580 4.147301
## 6 6.946892 6.173374 6.398175 5.806166 6.272329 6.545788 6.747217 7.180959
##        438      439      440      441      442      443      444      445
## 1 9.396533 9.435637 8.099988 8.384080 7.713189 7.607664 7.769558 8.369895
## 2 4.811409 4.695929 2.433801 2.937692 2.207332 2.192461 2.239337 2.871156
## 3 8.394236 8.484083 7.006532 7.350912 6.477458 6.351316 6.518089 7.288150
## 4 6.386947 6.327543 4.552303 5.079909 4.380978 4.219854 4.422982 4.931360
## 5 4.213632 4.342741 4.516857 4.509393 4.608229 4.755074 4.637509 3.918161
## 6 7.707796 7.700430 6.054304 6.446442 5.755888 5.609025 5.811139 6.418899
##        446      447      448      449      450      451      452      453
## 1 8.869383 7.692356 7.719083 7.662880 7.734779 8.619425 7.510000 7.420544
## 2 4.315338 2.223077 2.207460 2.126064 2.281549 4.610171 2.238968 2.096565
## 3 7.822260 6.503523 6.592742 6.535974 6.588139 7.643669 6.322861 6.315283
## 4 5.892565 4.313539 4.358067 4.262430 4.358030 5.922856 4.230132 4.095576
## 5 4.052052 4.377493 4.626360 4.619462 4.290924 4.436440 4.659548 4.698128
## 6 7.168870 5.714462 5.725384 5.655226 5.767098 7.013088 5.561251 5.419305
##        454      455      456      457      458      459      460      461
## 1 7.488797 8.615112 8.280416 8.613939 8.529698 7.413953 7.197961 7.441333
## 2 2.816811 4.549028 4.088681 4.450875 4.516870 2.377775 2.175860 2.581875
## 3 6.201144 7.628370 7.338629 7.770650 7.771267 6.463171 6.189770 6.350729
## 4 4.575975 5.918794 5.464389 5.749648 5.801327 4.266589 4.034746 4.354303
## 5 5.115979 4.321729 4.205509 4.252759 4.258883 4.236988 4.789795 4.385829
## 6 5.704355 7.016989 6.589745 6.913673 6.866815 5.484535 5.216250 5.566897
##        462      463      464      465      466      467      468      469
## 1 7.224008 7.129990 7.081032 6.761263 6.784776 8.163381 7.276556 7.067634
## 2 2.197525 2.207914 2.436963 2.400811 2.744376 4.323182 2.345760 2.548814
## 3 6.150612 6.113243 6.000826 5.995825 6.265945 7.375314 6.308918 6.388907
## 4 4.028929 4.046035 4.100801 3.940852 4.014623 5.454107 3.942868 4.149291
## 5 4.871657 4.859767 5.057480 4.982831 4.910892 4.372635 4.541440 4.648344
## 6 5.245377 5.175440 5.168781 4.825356 4.830816 6.492417 5.264318 5.133202
##        470      471      472      473      474      475      476      477
## 1 6.854434 6.816620 6.708850 6.594683 6.547902 7.501061 7.637258 7.206421
## 2 2.734118 2.311425 2.560930 2.499788 3.048901 2.434451 2.523020 2.223730
## 3 6.323801 5.996607 5.921288 5.766964 5.546301 6.666256 6.654666 6.151680
## 4 4.089454 3.742729 3.729722 3.771861 4.165060 4.053967 4.237950 3.945356
## 5 4.973919 4.971853 5.181002 5.161492 5.472082 4.527575 4.374497 4.862825
## 6 4.901491 4.816208 4.722700 4.659061 4.806139 5.415982 5.640980 5.208138
##        478      479      480      481      482      483      484      485
## 1 8.130462 7.407656 7.165587 6.328683 6.331364 6.329978 6.225603 6.407568
## 2 2.819877 2.149619 2.407795 2.841677 3.062382 3.305435 3.354835 3.007909
## 3 7.232034 6.384794 6.121775 5.803910 5.637316 5.575392 6.127800 6.133862
## 4 4.658359 4.056417 4.119396 3.815854 3.967622 4.139027 4.014627 3.945221
## 5 4.341229 4.588992 4.776866 5.387882 5.594453 5.786301 5.679794 5.329406
## 6 6.105211 5.382604 5.214375 4.428172 4.526780 4.616956 4.359692 4.497564
##        486      487      488      489      490      491      492      493
## 1 6.249662 6.708037 6.500512 7.746032 8.298286 8.670417 7.692851 7.224881
## 2 2.935648 2.355052 2.761430 3.339171 3.627365 4.033745 3.245201 3.298803
## 3 5.880484 6.022019 6.037518 6.749983 7.341242 7.743312 6.605526 6.225869
## 4 3.898792 3.748954 3.856913 4.067660 4.515760 4.922601 4.029950 3.853652
## 5 5.440584 4.972136 5.232320 5.468533 5.317298 5.364747 5.458144 5.624994
## 6 4.392934 4.727043 4.539202 5.655817 6.220009 6.633606 5.634401 5.208921
##        494      495      496      497      498      499      500      501
## 1 5.413752 5.273091 5.426681 6.011801 5.542505 5.414893 5.810165 5.688309
## 2 3.852454 3.986370 4.203245 3.717331 3.612856 3.666547 3.612745 3.521661
## 3 4.881230 4.787928 5.205773 5.359640 4.929451 4.699697 5.121802 4.887289
## 4 2.137355 2.335780 2.705197 2.322917 1.885295 1.925584 2.012924 1.880862
## 5 5.924585 6.035621 6.099197 5.645035 5.731891 5.820200 5.672489 5.683894
## 6 2.874711 2.815571 3.076628 3.570270 2.982151 2.867755 3.260115 3.150398
##        502      503      504      505      506
## 1 5.506603 5.730311 5.775209 5.732539 5.991382
## 2 4.294822 4.194855 4.555464 4.415418 4.255945
## 3 4.737543 4.960431 4.668497 4.734780 5.374542
## 4 2.309307 2.174338 2.764118 2.545516 2.378712
## 5 6.417801 6.310447 6.682914 6.547413 6.324684
## 6 3.056424 3.190441 3.518096 3.391335 3.469554
## 
## $totss
## [1] 748534.8
## 
## $withinss
## [1] 17974.37 26811.41 21548.41 22667.20 55771.90 25160.33
## 
## $tot.withinss
## [1] 169933.6
## 
## $betweenss
## [1] 578601.2
myclust<-data.frame(km_bs2$cluster)
boston_scaled2$clust<-km_bs2$cluster
head(boston_scaled2)
##         crim         zn      indus       chas        nox        rm
## 1 -0.4193669  0.2845483 -1.2866362 -0.2723291 -0.1440749 0.4132629
## 2 -0.4169267 -0.4872402 -0.5927944 -0.2723291 -0.7395304 0.1940824
## 3 -0.4169290 -0.4872402 -0.5927944 -0.2723291 -0.7395304 1.2814456
## 4 -0.4163384 -0.4872402 -1.3055857 -0.2723291 -0.8344581 1.0152978
## 5 -0.4120741 -0.4872402 -1.3055857 -0.2723291 -0.8344581 1.2273620
## 6 -0.4166314 -0.4872402 -1.3055857 -0.2723291 -0.8344581 0.2068916
##          age      dis        rad        tax    ptratio     black
## 1 -0.1198948 0.140075 -0.9818712 -0.6659492 -1.4575580 0.4406159
## 2  0.3668034 0.556609 -0.8670245 -0.9863534 -0.3027945 0.4406159
## 3 -0.2655490 0.556609 -0.8670245 -0.9863534 -0.3027945 0.3960351
## 4 -0.8090878 1.076671 -0.7521778 -1.1050216  0.1129203 0.4157514
## 5 -0.5106743 1.076671 -0.7521778 -1.1050216  0.1129203 0.4406159
## 6 -0.3508100 1.076671 -0.7521778 -1.1050216  0.1129203 0.4101651
##        lstat       medv clust
## 1 -1.0744990  0.1595278     6
## 2 -0.4919525 -0.1014239     6
## 3 -1.2075324  1.3229375     6
## 4 -1.3601708  1.1815886     6
## 5 -1.0254866  1.4860323     6
## 6 -1.0422909  0.6705582     6
lda.fit_bs2<-lda(clust~., data = boston_scaled2 )
lda.fit_bs2
## Call:
## lda(clust ~ ., data = boston_scaled2)
## 
## Prior probabilities of groups:
##          1          2          3          4          5          6 
## 0.10079051 0.19960474 0.09486166 0.20553360 0.12845850 0.27075099 
## 
## Group means:
##         crim          zn        indus       chas         nox          rm
## 1 -0.4149170  2.55535505 -1.228758914 -0.1951310 -1.21919439  0.78676843
## 2  0.3880377 -0.48724019  1.165421314 -0.2723291  0.98659851 -0.28553884
## 3 -0.3613809 -0.09419977 -0.474086929  1.5321752 -0.12487357  1.27068222
## 4 -0.3580718 -0.46023584 -0.003188584 -0.2723291 -0.09478548 -0.35414265
## 5  1.4172264 -0.48724019  1.069802298  0.4545202  1.34622349 -0.73713928
## 6 -0.4055840  0.02149547 -0.740804469 -0.2723291 -0.79649957  0.09099544
##          age        dis        rad        tax    ptratio       black
## 1 -1.4488239  1.7464736 -0.7048880 -0.5692695 -0.8353442  0.34924852
## 2  0.7651453 -0.7898745  1.1388129  1.2431405  0.6932747  0.04498348
## 3  0.2307707 -0.3386056 -0.4961654 -0.7220694 -1.1226766  0.32813467
## 4  0.4093998 -0.2612071 -0.5865335 -0.4342609  0.2608189  0.19191309
## 5  0.8557425 -0.9615698  1.2885597  1.2934457  0.4142248 -1.68787016
## 6 -0.8223904  0.7053125 -0.5694290 -0.7355910 -0.2013102  0.37698635
##        lstat       medv
## 1 -0.9773530  0.8760790
## 2  0.6734731 -0.5987824
## 3 -0.6138415  1.4407282
## 4  0.1508360 -0.2838601
## 5  1.1961180 -0.8078336
## 6 -0.5996059  0.2092896
## 
## Coefficients of linear discriminants:
##                 LD1         LD2         LD3         LD4         LD5
## crim     0.04811996 -0.28556378 -0.55488255  0.49400398  0.05329096
## zn      -0.13738829 -1.83004313  0.34546140 -0.26802062 -0.87758918
## indus    0.74925386 -0.10015651  0.61607026 -0.42031079  0.25109137
## chas     0.13287282 -0.13228082 -0.94523359 -0.16829634  0.04786106
## nox      1.21764057 -0.81216848 -0.12506389  0.27633410  0.13213424
## rm      -0.12060003 -0.04058521 -0.02502279 -0.75468374  0.21331834
## age      0.17397462  0.34382124 -0.07430813 -0.37956005 -0.95205471
## dis     -0.36273454 -0.54652248  0.11546588  0.26210162  0.59195828
## rad      0.61453519  0.40958433  0.29006265 -0.40963042  1.56473994
## tax      0.75124298 -1.03741454  0.22707980 -0.17126395 -0.61781814
## ptratio  0.36217649 -0.18603253  0.30060517  0.16017164 -0.53729844
## black   -0.27542772  0.27016025  0.77143821 -0.87012879  0.23445845
## lstat    0.48988940 -0.40861927 -0.53017288 -0.23295699 -0.06758426
## medv     0.22977036 -0.57759705 -0.86635437 -0.06977308 -0.10361245
## 
## Proportion of trace:
##    LD1    LD2    LD3    LD4    LD5 
## 0.7285 0.1498 0.0750 0.0298 0.0168
lda.arrows <- function(x, myscale = 1, arrow_heads = 0.1, color = "red", tex = 0.75, choices = c(1,2)){
  heads <- coef(x)
  arrows(x0 = 0, y0 = 0, 
         x1 = myscale * heads[,choices[1]], 
         y1 = myscale * heads[,choices[2]], col=color, length = arrow_heads)
  text(myscale * heads[,choices], labels = row.names(heads), 
       cex = tex, col=color, pos=3)
}
plot(lda.fit_bs2, dimen = 2)
lda.arrows(lda.fit_bs2, myscale = 3)

I think the dataset could be grouped more easily by a lower number of clusters, though I’m not sure what would be the minimum number. The top three most relevant variables according to our bi-plot are “zn”, “nox”, and “tax”.

Super.Bonus

Additional ways for visualising LDA:

library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:MASS':
## 
##     select
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
model_predictors <- dplyr::select(train, -crime)
dim(model_predictors)
## [1] 404  13
dim(lda.fit$scaling)
## [1] 13  3
matrix_product <- as.matrix(model_predictors) %*% lda.fit$scaling
matrix_product <- as.data.frame(matrix_product)
plot_ly(x = matrix_product$LD1, y = matrix_product$LD2, z = matrix_product$LD3, type= 'scatter3d', mode='markers', color = train$crim)
k_means_matpro <- kmeans(matrix_product, centers = 6, iter.max = 10, nstart = 1, trace=FALSE)
head(train)
##              zn      indus       chas        nox          rm        age
## 364 -0.48724019  1.0149946  3.6647712  1.8580364 -0.68548625  0.7256101
## 227 -0.48724019 -0.7196100 -0.2723291 -0.4374877  2.49832448  0.6367966
## 431 -0.48724019  1.0149946 -0.2723291  0.2528955  0.09018512  0.6225864
## 13   0.04872402 -0.4761823 -0.2723291 -0.2648919 -0.56308673 -1.0506607
## 185 -0.48724019 -1.2647715 -0.2723291 -0.5755644 -0.96871304  0.7540305
## 282  0.37030254 -1.1379558 -0.2723291 -0.9647679  0.97260025 -1.1146064
##            dis        rad        tax    ptratio       black      lstat
## 364 -0.8977222  1.6596029  1.5294129  0.8057784 -0.03980543  0.2782411
## 227 -0.2751294 -0.1779443 -0.6006817 -0.4875567  0.33633840 -1.3335641
## 431 -0.8274371  1.6596029  1.5294129  0.8057784 -2.99276453  0.6983467
## 13   0.7863653 -0.5224844 -0.5769480 -1.5037485  0.37051338  0.4280788
## 185 -0.3833114 -0.7521778 -1.2770905 -0.3027945  0.37599013  0.1858179
## 282  0.6884411 -0.5224844 -1.1406221 -1.6423201  0.38946296 -1.1291127
##            medv    crime
## 364 -0.62332733     high
## 227  1.63825412 med_high
## 431 -0.87340605     high
## 13  -0.09055093  med_low
## 185  0.42047949  med_low
## 282  1.39904839      low
myclust <- NA
train$cl<-myclust
boston_scaled2$cl<-myclust
head(boston_scaled2)
##         crim         zn      indus       chas        nox        rm
## 1 -0.4193669  0.2845483 -1.2866362 -0.2723291 -0.1440749 0.4132629
## 2 -0.4169267 -0.4872402 -0.5927944 -0.2723291 -0.7395304 0.1940824
## 3 -0.4169290 -0.4872402 -0.5927944 -0.2723291 -0.7395304 1.2814456
## 4 -0.4163384 -0.4872402 -1.3055857 -0.2723291 -0.8344581 1.0152978
## 5 -0.4120741 -0.4872402 -1.3055857 -0.2723291 -0.8344581 1.2273620
## 6 -0.4166314 -0.4872402 -1.3055857 -0.2723291 -0.8344581 0.2068916
##          age      dis        rad        tax    ptratio     black
## 1 -0.1198948 0.140075 -0.9818712 -0.6659492 -1.4575580 0.4406159
## 2  0.3668034 0.556609 -0.8670245 -0.9863534 -0.3027945 0.4406159
## 3 -0.2655490 0.556609 -0.8670245 -0.9863534 -0.3027945 0.3960351
## 4 -0.8090878 1.076671 -0.7521778 -1.1050216  0.1129203 0.4157514
## 5 -0.5106743 1.076671 -0.7521778 -1.1050216  0.1129203 0.4406159
## 6 -0.3508100 1.076671 -0.7521778 -1.1050216  0.1129203 0.4101651
##        lstat       medv clust cl
## 1 -1.0744990  0.1595278     6 NA
## 2 -0.4919525 -0.1014239     6 NA
## 3 -1.2075324  1.3229375     6 NA
## 4 -1.3601708  1.1815886     6 NA
## 5 -1.0254866  1.4860323     6 NA
## 6 -1.0422909  0.6705582     6 NA
head(train)
##              zn      indus       chas        nox          rm        age
## 364 -0.48724019  1.0149946  3.6647712  1.8580364 -0.68548625  0.7256101
## 227 -0.48724019 -0.7196100 -0.2723291 -0.4374877  2.49832448  0.6367966
## 431 -0.48724019  1.0149946 -0.2723291  0.2528955  0.09018512  0.6225864
## 13   0.04872402 -0.4761823 -0.2723291 -0.2648919 -0.56308673 -1.0506607
## 185 -0.48724019 -1.2647715 -0.2723291 -0.5755644 -0.96871304  0.7540305
## 282  0.37030254 -1.1379558 -0.2723291 -0.9647679  0.97260025 -1.1146064
##            dis        rad        tax    ptratio       black      lstat
## 364 -0.8977222  1.6596029  1.5294129  0.8057784 -0.03980543  0.2782411
## 227 -0.2751294 -0.1779443 -0.6006817 -0.4875567  0.33633840 -1.3335641
## 431 -0.8274371  1.6596029  1.5294129  0.8057784 -2.99276453  0.6983467
## 13   0.7863653 -0.5224844 -0.5769480 -1.5037485  0.37051338  0.4280788
## 185 -0.3833114 -0.7521778 -1.2770905 -0.3027945  0.37599013  0.1858179
## 282  0.6884411 -0.5224844 -1.1406221 -1.6423201  0.38946296 -1.1291127
##            medv    crime cl
## 364 -0.62332733     high NA
## 227  1.63825412 med_high NA
## 431 -0.87340605     high NA
## 13  -0.09055093  med_low NA
## 185  0.42047949  med_low NA
## 282  1.39904839      low NA
rownames(train)
##   [1] "364" "227" "431" "13"  "185" "282" "491" "403" "43"  "243" "446"
##  [12] "273" "46"  "311" "295" "371" "89"  "274" "473" "75"  "35"  "325"
##  [23] "250" "333" "204" "48"  "138" "413" "14"  "23"  "211" "105" "251"
##  [34] "398" "224" "155" "368" "447" "218" "16"  "136" "285" "10"  "244"
##  [45] "29"  "226" "493" "197" "32"  "163" "97"  "321" "6"   "81"  "466"
##  [56] "280" "269" "365" "489" "187" "254" "88"  "275" "450" "287" "166"
##  [67] "412" "426" "149" "30"  "76"  "310" "394" "61"  "192" "352" "399"
##  [78] "257" "164" "485" "40"  "372" "357" "152" "216" "208" "69"  "125"
##  [89] "90"  "307" "288" "276" "343" "259" "484" "60"  "401" "267" "99" 
## [100] "147" "465" "408" "261" "84"  "331" "93"  "45"  "461" "133" "428"
## [111] "390" "460" "500" "329" "478" "501" "270" "355" "323" "454" "37" 
## [122] "58"  "381" "477" "22"  "198" "123" "253" "487" "283" "9"   "207"
## [133] "305" "505" "416" "191" "469" "146" "302" "317" "359" "225" "451"
## [144] "496" "231" "49"  "300" "113" "128" "213" "67"  "238" "330" "143"
## [155] "470" "435" "332" "183" "341" "235" "98"  "223" "291" "109" "91" 
## [166] "289" "452" "498" "228" "95"  "497" "324" "481" "17"  "221" "410"
## [177] "181" "293" "137" "423" "86"  "456" "444" "202" "34"  "309" "326"
## [188] "482" "492" "201" "348" "506" "131" "245" "472" "230" "278" "405"
## [199] "175" "351" "12"  "252" "7"   "171" "360" "124" "440" "335" "3"  
## [210] "220" "119" "169" "479" "344" "358" "336" "504" "170" "173" "458"
## [221] "380" "292" "400" "140" "363" "151" "83"  "237" "82"  "312" "248"
## [232] "26"  "392" "393" "379" "129" "464" "290" "222" "50"  "132" "11" 
## [243] "373" "156" "475" "157" "266" "421" "180" "425" "2"   "419" "160"
## [254] "369" "346" "112" "356" "322" "318" "94"  "256" "5"   "145" "114"
## [265] "70"  "345" "241" "411" "294" "384" "306" "73"  "308" "427" "21" 
## [276] "168" "316" "196" "328" "319" "167" "42"  "296" "375" "236" "334"
## [287] "362" "20"  "120" "391" "107" "441" "194" "476" "387" "406" "51" 
## [298] "249" "102" "18"  "494" "420" "337" "195" "409" "366" "467" "299"
## [309] "141" "265" "92"  "214" "8"   "55"  "28"  "448" "449" "121" "179"
## [320] "315" "217" "386" "263" "407" "79"  "457" "188" "142" "453" "205"
## [331] "178" "455" "135" "38"  "437" "174" "52"  "396" "327" "104" "101"
## [342] "502" "429" "153" "495" "71"  "184" "370" "47"  "117" "490" "340"
## [353] "106" "19"  "165" "126" "144" "503" "395" "154" "462" "385" "240"
## [364] "111" "161" "417" "87"  "85"  "159" "499" "303" "279" "66"  "430"
## [375] "24"  "246" "247" "347" "404" "314" "103" "80"  "418" "397" "353"
## [386] "339" "127" "349" "434" "468" "177" "41"  "77"  "63"  "414" "382"
## [397] "488" "162" "74"  "439" "376" "301" "436" "442"
rownames(boston_scaled2)
##   [1] "1"   "2"   "3"   "4"   "5"   "6"   "7"   "8"   "9"   "10"  "11" 
##  [12] "12"  "13"  "14"  "15"  "16"  "17"  "18"  "19"  "20"  "21"  "22" 
##  [23] "23"  "24"  "25"  "26"  "27"  "28"  "29"  "30"  "31"  "32"  "33" 
##  [34] "34"  "35"  "36"  "37"  "38"  "39"  "40"  "41"  "42"  "43"  "44" 
##  [45] "45"  "46"  "47"  "48"  "49"  "50"  "51"  "52"  "53"  "54"  "55" 
##  [56] "56"  "57"  "58"  "59"  "60"  "61"  "62"  "63"  "64"  "65"  "66" 
##  [67] "67"  "68"  "69"  "70"  "71"  "72"  "73"  "74"  "75"  "76"  "77" 
##  [78] "78"  "79"  "80"  "81"  "82"  "83"  "84"  "85"  "86"  "87"  "88" 
##  [89] "89"  "90"  "91"  "92"  "93"  "94"  "95"  "96"  "97"  "98"  "99" 
## [100] "100" "101" "102" "103" "104" "105" "106" "107" "108" "109" "110"
## [111] "111" "112" "113" "114" "115" "116" "117" "118" "119" "120" "121"
## [122] "122" "123" "124" "125" "126" "127" "128" "129" "130" "131" "132"
## [133] "133" "134" "135" "136" "137" "138" "139" "140" "141" "142" "143"
## [144] "144" "145" "146" "147" "148" "149" "150" "151" "152" "153" "154"
## [155] "155" "156" "157" "158" "159" "160" "161" "162" "163" "164" "165"
## [166] "166" "167" "168" "169" "170" "171" "172" "173" "174" "175" "176"
## [177] "177" "178" "179" "180" "181" "182" "183" "184" "185" "186" "187"
## [188] "188" "189" "190" "191" "192" "193" "194" "195" "196" "197" "198"
## [199] "199" "200" "201" "202" "203" "204" "205" "206" "207" "208" "209"
## [210] "210" "211" "212" "213" "214" "215" "216" "217" "218" "219" "220"
## [221] "221" "222" "223" "224" "225" "226" "227" "228" "229" "230" "231"
## [232] "232" "233" "234" "235" "236" "237" "238" "239" "240" "241" "242"
## [243] "243" "244" "245" "246" "247" "248" "249" "250" "251" "252" "253"
## [254] "254" "255" "256" "257" "258" "259" "260" "261" "262" "263" "264"
## [265] "265" "266" "267" "268" "269" "270" "271" "272" "273" "274" "275"
## [276] "276" "277" "278" "279" "280" "281" "282" "283" "284" "285" "286"
## [287] "287" "288" "289" "290" "291" "292" "293" "294" "295" "296" "297"
## [298] "298" "299" "300" "301" "302" "303" "304" "305" "306" "307" "308"
## [309] "309" "310" "311" "312" "313" "314" "315" "316" "317" "318" "319"
## [320] "320" "321" "322" "323" "324" "325" "326" "327" "328" "329" "330"
## [331] "331" "332" "333" "334" "335" "336" "337" "338" "339" "340" "341"
## [342] "342" "343" "344" "345" "346" "347" "348" "349" "350" "351" "352"
## [353] "353" "354" "355" "356" "357" "358" "359" "360" "361" "362" "363"
## [364] "364" "365" "366" "367" "368" "369" "370" "371" "372" "373" "374"
## [375] "375" "376" "377" "378" "379" "380" "381" "382" "383" "384" "385"
## [386] "386" "387" "388" "389" "390" "391" "392" "393" "394" "395" "396"
## [397] "397" "398" "399" "400" "401" "402" "403" "404" "405" "406" "407"
## [408] "408" "409" "410" "411" "412" "413" "414" "415" "416" "417" "418"
## [419] "419" "420" "421" "422" "423" "424" "425" "426" "427" "428" "429"
## [430] "430" "431" "432" "433" "434" "435" "436" "437" "438" "439" "440"
## [441] "441" "442" "443" "444" "445" "446" "447" "448" "449" "450" "451"
## [452] "452" "453" "454" "455" "456" "457" "458" "459" "460" "461" "462"
## [463] "463" "464" "465" "466" "467" "468" "469" "470" "471" "472" "473"
## [474] "474" "475" "476" "477" "478" "479" "480" "481" "482" "483" "484"
## [485] "485" "486" "487" "488" "489" "490" "491" "492" "493" "494" "495"
## [496] "496" "497" "498" "499" "500" "501" "502" "503" "504" "505" "506"
train$cl <- boston_scaled2$clust[match(rownames(train), rownames(boston_scaled2))]
head(train)
##              zn      indus       chas        nox          rm        age
## 364 -0.48724019  1.0149946  3.6647712  1.8580364 -0.68548625  0.7256101
## 227 -0.48724019 -0.7196100 -0.2723291 -0.4374877  2.49832448  0.6367966
## 431 -0.48724019  1.0149946 -0.2723291  0.2528955  0.09018512  0.6225864
## 13   0.04872402 -0.4761823 -0.2723291 -0.2648919 -0.56308673 -1.0506607
## 185 -0.48724019 -1.2647715 -0.2723291 -0.5755644 -0.96871304  0.7540305
## 282  0.37030254 -1.1379558 -0.2723291 -0.9647679  0.97260025 -1.1146064
##            dis        rad        tax    ptratio       black      lstat
## 364 -0.8977222  1.6596029  1.5294129  0.8057784 -0.03980543  0.2782411
## 227 -0.2751294 -0.1779443 -0.6006817 -0.4875567  0.33633840 -1.3335641
## 431 -0.8274371  1.6596029  1.5294129  0.8057784 -2.99276453  0.6983467
## 13   0.7863653 -0.5224844 -0.5769480 -1.5037485  0.37051338  0.4280788
## 185 -0.3833114 -0.7521778 -1.2770905 -0.3027945  0.37599013  0.1858179
## 282  0.6884411 -0.5224844 -1.1406221 -1.6423201  0.38946296 -1.1291127
##            medv    crime cl
## 364 -0.62332733     high  5
## 227  1.63825412 med_high  3
## 431 -0.87340605     high  2
## 13  -0.09055093  med_low  6
## 185  0.42047949  med_low  4
## 282  1.39904839      low  6
nrow(train)
## [1] 404
plot_ly(x = matrix_product$LD1, y = matrix_product$LD2, z = matrix_product$LD3, type = "scatter3d", mode="markers", color = train$cl)

In light of my research, clustering made with K-means have turned out to be more informative than thes one based on crime classes.